package view.plugin
{
	//按钮提示:如鼠标移到托管按钮提示
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import flash3.framework.Map;
	import flash3.framework.Singleton;
	
	import global.Resource;
	
	public class TipsPanel extends Sprite
	{
		private var map:Map = null;
		private var panel:MovieClip = null;
		private var textField:TextField = null;
		public function TipsPanel()
		{
			super();
			map = new Map();
			
			panel = Resource.i.getMovieClip("common", "TipsBg");
//			panel = new MovieClip();
			addChild(panel);
			
			textField = new TextField();
			textField.x = -50;
			textField.y = -10;
			textField.width = 100;
			textField.height = 100;
			textField.wordWrap = true;
			textField.multiline = true;
			textField.mouseEnabled = false;
			var tf:TextFormat = textField.defaultTextFormat;
//			tf.color = 0xaf90f9;
			tf.color = 0xaf90f9;
//			tf.size = 13;
//			tf.font = "黑体";
			textField.defaultTextFormat = tf;
			addChild(textField);
		}
		
		public function add(displayObj:EventDispatcher, t:String, point:Point):void
		{
			map.put(displayObj, {txt:t, point:point});
			displayObj.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			displayObj.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onMouseOut(evt:MouseEvent):void
		{
			if(parent)
				parent.removeChild(this);
		}
		
		private function onMouseOver(evt:MouseEvent):void
		{
			var keys:Array = map.keys();
			for(var i:uint = 0; i < keys.length; i++)
			{
				if(evt.target == keys[i])
				{
					var obj:Object = map.getValue(keys[i]);
					x = obj.point.x;
					y = obj.point.y;
					textField.text = obj.txt;
//					trace(textField.width,textField.height);
//					trace(textField.textWidth,textField.textHeight);
//					textField.width = textField.textWidth;
//					textField.height = textField.textHeight;
					panel.width = textField.textWidth + 20;
					panel.height = textField.textHeight + 20;
					textField.x = -45;
					textField.y = -15;
					ChessLobby.tops.addChild(this);
					break;
				}
			}
		}
		
		static public function get i():TipsPanel
		{
			return Singleton.getInstanceOrCreate(TipsPanel) as TipsPanel;
		}
	}
}